package org.jeecg.modules.system.util;

import org.springframework.util.StringUtils;

import java.util.HashSet;
import java.util.Set;

public class ContentTypeCheck {

    private static final Set<String> ACCEPT_CONTENT_TYPE = new HashSet<>();

    static {
        ACCEPT_CONTENT_TYPE.add("text/plain".trim()); //.txt
        ACCEPT_CONTENT_TYPE.add("text/csv".trim()); //.csv
//        ACCEPT_CONTENT_TYPE.add("text/css".trim()); //.css
//        ACCEPT_CONTENT_TYPE.add("text/html".trim()); //.htm .html
//        ACCEPT_CONTENT_TYPE.add("text/javascript".trim()); //.js
        ACCEPT_CONTENT_TYPE.add("text/rtf".trim()); //.rtf
        ACCEPT_CONTENT_TYPE.add("text/xml".trim()); //.xml
        ACCEPT_CONTENT_TYPE.add("image/jp2".trim()); //.jp2
        ACCEPT_CONTENT_TYPE.add("image/jpeg".trim()); //.jpg .jpe .jpeg
        ACCEPT_CONTENT_TYPE.add("image/vnd.dwg".trim()); //.dwg
        ACCEPT_CONTENT_TYPE.add("image/vnd.dxf".trim()); //.dxf
        ACCEPT_CONTENT_TYPE.add("image/bmp".trim()); //.bmp
        ACCEPT_CONTENT_TYPE.add("image/png".trim()); //.png
        ACCEPT_CONTENT_TYPE.add("image/vnd.svf".trim()); //.svf
        ACCEPT_CONTENT_TYPE.add("image/tiff".trim()); //.tif .tiff
        ACCEPT_CONTENT_TYPE.add("image/gif".trim()); //.gif
        ACCEPT_CONTENT_TYPE.add("audio/3gpp".trim()); //.3gpp .3gp
        ACCEPT_CONTENT_TYPE.add("audio/ac3".trim()); //.ac3
        ACCEPT_CONTENT_TYPE.add("audio/mpeg".trim()); //.mp2 .mp3
        ACCEPT_CONTENT_TYPE.add("audio/mp4".trim()); //.mp4
        ACCEPT_CONTENT_TYPE.add("audio/basic".trim()); //.au
        ACCEPT_CONTENT_TYPE.add("audio/ogg".trim()); //.ogg
        ACCEPT_CONTENT_TYPE.add("video/3gpp".trim()); //.3gpp .3gp
        ACCEPT_CONTENT_TYPE.add("video/mpeg".trim()); //.mp2 .mpeg .mpg
        ACCEPT_CONTENT_TYPE.add("video/mp4".trim()); //.mp4
        ACCEPT_CONTENT_TYPE.add("video/quicktime".trim()); //.mov
        ACCEPT_CONTENT_TYPE.add("video/webm".trim()); //.webm
        ACCEPT_CONTENT_TYPE.add("video/avi".trim()); //.avi
        ACCEPT_CONTENT_TYPE.add("video/x-ms-wmv".trim()); //.wmv
//        ACCEPT_CONTENT_TYPE.add("application/xhtml+xml".trim()); //.xhtml
//        ACCEPT_CONTENT_TYPE.add("application/javascript".trim()); //.js
        ACCEPT_CONTENT_TYPE.add("application/rtf".trim()); //.rtf
        ACCEPT_CONTENT_TYPE.add("application/xml".trim()); //.xml
        ACCEPT_CONTENT_TYPE.add("application/xml-dtd".trim()); //.dtd
        ACCEPT_CONTENT_TYPE.add("application/json".trim()); //.json
        ACCEPT_CONTENT_TYPE.add("application/msword".trim()); //.doc .dot
        ACCEPT_CONTENT_TYPE.add("application/vnd.openxmlformats-officedocument.wordprocessingml.document".trim()); //.docx
        ACCEPT_CONTENT_TYPE.add("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet".trim()); //.xlsx
        ACCEPT_CONTENT_TYPE.add("application/vnd.openxmlformats-officedocument.spreadsheetml.template".trim()); //.xltx
        ACCEPT_CONTENT_TYPE.add("application/vnd.openxmlformats-officedocument.presentationml.template".trim()); //.potx
        ACCEPT_CONTENT_TYPE.add("application/vnd.openxmlformats-officedocument.presentationml.slideshow".trim()); //.ppsx
        ACCEPT_CONTENT_TYPE.add("application/vnd.openxmlformats-officedocument.presentationml.presentation".trim()); //.pptx
        ACCEPT_CONTENT_TYPE.add("application/vnd.openxmlformats-officedocument.presentationml.slide".trim()); //.sldx
        ACCEPT_CONTENT_TYPE.add("application/vnd.openxmlformats-officedocument.wordprocessingml.template".trim()); //.dotx
        ACCEPT_CONTENT_TYPE.add("application/vnd.ms-excel.addin.macroEnabled.12".trim()); //.xlsm
        ACCEPT_CONTENT_TYPE.add("application/vnd.ms-excel.sheet.binary.macroEnabled.12".trim()); //.xlsb
        ACCEPT_CONTENT_TYPE.add("application/vnd.ms-asf".trim()); //.asf
        ACCEPT_CONTENT_TYPE.add("application/vnd.ms-visio.drawing".trim()); //.vsdx
        ACCEPT_CONTENT_TYPE.add("application/pdf".trim()); //.pdf
        ACCEPT_CONTENT_TYPE.add("application/vnd.ms-project".trim()); //.mpp
        ACCEPT_CONTENT_TYPE.add("application/ogg".trim()); //.ogg
        ACCEPT_CONTENT_TYPE.add("application/vnd.ms-powerpoint".trim()); //.pot .pps .ppt
        ACCEPT_CONTENT_TYPE.add("application/vnd.ms-works".trim()); //.wdb .wps
        ACCEPT_CONTENT_TYPE.add("application/vnd.ms-excel".trim()); //.xlc .xlm .xls .xlt .xlw
        ACCEPT_CONTENT_TYPE.add("application/vnd.ms-excel.sheet.macroEnabled.12".trim()); //.xlsm
        ACCEPT_CONTENT_TYPE.add("application/zip".trim()); //.zip
    }

    public static boolean contains(String contentType) {
        if (StringUtils.isEmpty(contentType)) {
            return false;
        }
        return ACCEPT_CONTENT_TYPE.contains(contentType);
    }

    public static void main(String[] args) {
        System.out.println(contains("application/zip"));
    }
}
